﻿
using bbtpClient.Entities;

namespace bbtpClient.Controllers
{
    public static class TransportManagerController
    {
        public static void ShowAddTransportCompanyForm()
        {
            AddEditTransportCompanyForm form = new AddEditTransportCompanyForm("Добавить транспортную компанию", new TransportCompany());
            form.Show();
        }

        public static void ShowEditTransportCompaniesListForm()
        {
            TransportCompanyHead[] companies = TransportCompanyController.GetTransportCompaniesList();
            EditTransportCompaniesListForm form = new EditTransportCompaniesListForm(companies);
            form.Show();
        }

        public static void ShowSetTransportCompanyForOrder()
        {
            TransportCompanyHead[] companies = TransportCompanyController.GetTransportCompaniesList();
            OrderHead[] orders = OrderController.GetReadyOrders();
            SetTransportCompanyOrderOrReturnForm form = new SetTransportCompanyOrderOrReturnForm(OrderType.ORDINARY, companies, orders);
            form.Show();
        }

        public static void ShowSetTransportCompanyForReturnOrder()
        {
            TransportCompanyHead[] companies = TransportCompanyController.GetTransportCompaniesList();
            OrderHead[] orders = OrderController.GetOrdersForReturn();
            SetTransportCompanyOrderOrReturnForm form = new SetTransportCompanyOrderOrReturnForm(OrderType.FOR_RETURN, companies, orders);
            form.Show();
        }

        public static void SaveTransportCompany(TransportCompany company, AddEditTransportCompanyForm form)
        {
            TransportCompanyController.SaveTransportCompany(company);
            form.Close();
        }

        public static void ShowEditTransportCompanyForm(long transportCompanyId)
        {
            TransportCompany company = TransportCompanyController.GetTransportCompany(transportCompanyId);
            AddEditTransportCompanyForm form = new AddEditTransportCompanyForm(company.name, company);
            form.Show();
        }

        public static void SetTransportCompanyForOrder(long transportCompanyId, long orderId, SetTransportCompanyOrderOrReturnForm form)
        {
            OrderController.SetTransportCompanyForOrder(orderId, transportCompanyId);
            form.DeleteSelectedOrderFromList();
        }

        public static void DeleteTransportCompany(long transportCompanyId, EditTransportCompaniesListForm form)
        {
            TransportCompanyController.DeleteTransportCompany(transportCompanyId);
            form.DeleteSelectedCompanyFromList();
        }
    }
}
